/*
* Alberto De Pena
* Applied Algorithms
* surjections.cpp
*/
#include <iostream>
#include <fstream>
using namespace std;

long long combination( long long n, long long i )
{
	if( i == 0 || n == 0 || i == n )
		return 1;
	else
		return combination( n -1, i -1 ) + combination( n - 1, i );
}

long long factorial( long long m )
{
	 if ( (m == 0) || (m == 1) )  
       return 1;
	else
       return m * factorial( m - 1 ); 
}

long long surgection( long long m, long long n )
{
	if( n == 1 )
		return 1;
	else if( m < n )
		return 0;
	else if( m == n )
		return factorial( m );
	else if( n > 1 && m > n )
	{
		long long temp = n;
		for( long long i = 1; i < m; i++ )
			temp *= n;

		long long total = 0;
		for( long long i = 1; i <= n - 1; i++ )
			total += combination( n, i ) * surgection( m, i );

		return temp - total;
	}
}

void main()
{
	ifstream fin( "surjections.in" );
	ofstream fout( "surjections.out" );
	long long m = 0;
	long long n = 0;

	while( !fin.eof() )
	{
		fin >> m >> n;
		if( m != 0 && n != 0 )
		{
			fout << "s(" << m << "," << n << ") = " << surgection( m,n ) << endl;
		}
	}
	
	fin.close();
	fout.close();
}